<ul class="am-list">
    <li class="am-padding-xs am-padding-left-sm"><?= $timelog_comment_num; ?>条评论</li>
    <?php foreach ($comment as $key => $value) : ?>
        <li class="am-padding-sm">
            <div class="tm-group">
                <div class="tm-group-head">
                    <a href="<?= $label->url('Master-Article-user', ['id' => $value['user_id']]); ?>"><img src="<?= $value['user_head']; ?>" class="am-img-thumbnail" alt="" width="48" height="48"></a>
                </div>
                <div class="tm-group-item">
                    <div class="am-cf am-text-sm">
                        <div class="am-fl">
                            <a class="am-link-muted" href="<?= $label->url('Master-Article-user', ['id' => $value['user_id']]); ?>"><?= $value['user_name']; ?></a>
                            <time datetime="<?= date('Y-m-d H:i', $value['timelog_comment_time']); ?>" title="<?= date('Y-m-d H:i', $value['timelog_comment_time']); ?>">评论 <?= $label->timing($value['timelog_comment_time']); ?></time>
                        </div>

                        <div class="am-fr">
                            <div class="am-text-right">
                                <a href="javascript:;" class="am-vertical-align-middle tm-reply am-link-muted" title="<?= $value['user_name']; ?>"><i class="am-icon-reply"></i>
                                </a>
                                <?php if ($_SESSION['user']['user_group_id'] == 1): ?>
                                <a href="<?= $label->url('Master-Article-comment', ['id' => $value['timelog_comment_id'], 'method' => 'DELETE']); ?>" class="am-vertical-align-middle tm-reply am-link-muted ajax-click ajax-delete" msg="确定删除吗？将无法恢复的！" title="<?= $value['user_name']; ?>"><i class="am-icon-remove"></i>
                                    <?php endif; ?>
                                </a>
                                <span class="am-badge am-round"><?= $value['timelog_comment_floor']; ?></span>
                            </div>
                        </div>
                    </div>
                    <div class="am-margin-top-xs">
                        <?= htmlspecialchars_decode($value['timelog_comment']); ?>
                    </div>

                </div>
            </div>
        </li>
    <?php endforeach; ?>
</ul>

<?php if ($login === true): ?>
    <form action="<?= $label->url('Master-Article-addComment'); ?>" class="ajax-submit" method="POST">
        <input type="hidden" name="id" value="<?= $timelog_id; ?>">
        <ul class="am-list">
            <li class="am-padding-xs am-text-sm">添加评论</li>
            <li class="am-padding-xs">
                <textarea class="am-form-field tm-addcomment" rows="5" placeholder="输入框使用MarkDown语法"></textarea>
                <textarea class="am-hide" name="comment"></textarea>
                <a href="https://zh.wikipedia.org/wiki/Markdown" target="_blank" class="am-text-sm"><i class="am-icon-lightbulb-o"></i> MarkDown维基</a>
                <button class="am-btn  am-btn-xs am-btn-primary">评论</button>
            </li>
        </ul>
    </form>
    <script type="text/javascript">
        $(function () {
            var converter = new showdown.Converter()
            $(".tm-addcomment").on('blur', function () {
                var html = converter.makeHtml($(this).val());
                $("textarea[name=comment]").val(html)
            })

            $(".tm-reply").on("click", function () {
                var user = $(this).attr("title");
                var html = $('.tm-addcomment').val();
                if (html.length > 0) {
                    html += "\r\n";
                }
                html += "@" + user + "  ";
                $('.tm-addcomment').val(html).focus();
            })
        })
    </script>
<?php endif; ?>